﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SilverlightControlStyle.Controls
{
    /// <summary>
    /// 右下角提示信息控件
    /// </summary>
    public class TipInfoEx : Control
    {
        private Storyboard _storyboard;

        public bool IsBegion { get; set; }

        public TipInfoEx()
        {
            DefaultStyleKey = typeof(TipInfoEx);

            IsBegion = true;
        }

        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            Grid templateChild = GetTemplateChild("LayoutRoot") as Grid;
            if (templateChild != null)
            {
                _storyboard = templateChild.Resources["XWaitPointStoryboard"] as Storyboard;
            }
            if (IsBegion)
            {
                BeginStoryboard();
            }
        }

        /// <summary>
        /// 提示信息
        /// </summary>
        public string WaitMessage
        {
            get { return (string)GetValue(WaitMessageProperty); }
            set { SetValue(WaitMessageProperty, value); }
        }

        // Using a DependencyProperty as the backing store for WaitMessage.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty WaitMessageProperty =
            DependencyProperty.Register("WaitMessage", typeof(string), typeof(TipInfoEx), null);

        /// <summary>
        /// 启动动画
        /// </summary>
        public void BeginStoryboard()
        {
            if (_storyboard != null)
            {
                _storyboard.Begin();
            }
        }

        /// <summary>
        /// 停止动画
        /// </summary>
        public void StopStoryboard()
        {
            if (_storyboard != null)
            {
                _storyboard.Stop();
            }
        }
    }
}
